// @ts-nocheck
import { createRouter, createWebHashHistory } from 'vue-router';
import Home from '../views/Home.vue';
// import Login from '../views/Login.vue';
// import Register from '../views/Register.vue';
import TestNet from '../views/TestNet.vue';
import Product from '../views/Product.vue';
import ProductDetail from '../views/ProductDetail.vue';

import Movie from '../views/Movie.vue';
import MovieDetail from '../views/MovieDetail.vue';
import MovieSite from '../views/MovieSite.vue';
import Article from '../views/Article.vue';
import ArticleDetail from '../views/ArticleDetail.vue';
import TodoList from '../views/TodoList.vue';
import About from '../views/About.vue'
import NotFound from '@/views/NotFound.vue';
const routes = [
  {
    path: '/',
    redirect: '/movie-site'
  },
  {
    path: '/movie-site',
    name: 'MovieSite',
    component: MovieSite,
    meta: {
      role: 'stu',
    },
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      role: 'admin',
    },
  },

  {
    path: '/about',
    name: 'About',
    component: About,
    meta: {
      role: 'stu',
    },
  },

  {
    path: '/movie',
    name: 'Movie',
    component: Movie,
    meta: {
      role: 'stu',
    },
  },
  {
    path: '/moviedetail',
    name: 'MovieDetail',
    component: MovieDetail,
    meta: {
      role: 'stu',
    },
  },
  {
    path: '/product',
    name: 'Product',
    component: Product,
    meta: {
      role: 'stu',
    },
  },
  {
    path: '/productdetail',
    name: 'ProductDetail',
    component: ProductDetail,
    meta: {
      role: 'stu',
    },
  },
  {
    path: '/article',
    name: 'Article',
    component: Article,
    meta: {
      role: 'stu',
    },
  },
  {
    path: '/articledetail',
    name: 'ArticleDetail',
    component: ArticleDetail,
    meta: {
      role: 'stu',
    },
  },

  // 注释掉多余的登录路由，因为MovieSite组件内部已经包含登录功能
  // {
  //   path: '/login',
  //   name: 'Login',
  //   component: Login,
  // },
  // {
  //   path: '/register',
  //   name: 'Register',
  //   component: Register,
  // },
  {
    path: '/todolist',
    name: 'TodoList',
    component: TodoList,
  },

  {
    path: '/testnet',
    name: 'TestNet',
    component: TestNet,
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: NotFound,
  },

  // {
  //   path: '*',
  //   redirect: '/404'
  // },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// router.beforeEach((to, from,next) => {
//   // ...
//   // 返回 false 以取消导航
//   const loginResult= sessionStorage.getItem('isLoggedIn');
  
//   if (to.name !== 'Login'&&to.name !== 'Register'&&!loginResult)
//      next({ name: 'Login' })
 
//    else next()



// })



export default router;